Repository navigation
Docker: hardened image and Compose deployment - #13
Open
Skyfuller1303 wants to merge 10 commits into
Open
Skyfuller1303 wants to merge 10 commits into
Skyfuller1303 wants to merge 10 commits into
Conversation
`craft-cloud-server healthcheck [--addr 127.0.0.1:8080]` sends GET /api/info over a plain TcpStream and exits 0 only on a 200 status line, within 3 s. Otherwise it exits 1 with one line on stderr. It prints nothing on stdout and adds no dependency. A container image without a shell or curl can use it as its health check. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ment packaging/docker holds a Dockerfile (Debian trixie build, distroless cc runtime as uid 65532, base images pinned by digest) and a Compose deployment: the server behind Caddy for TLS (acme, internal or custom certificates), with SQLite and the local disk by default and overlays for Postgres and S3. Secrets never reach a service's environment. A one-shot secrets-init service renders config.toml from a template and writes the secret files into a volume; every other service mounts only its own directory read-only. Every service has a read-only root, no capabilities and no-new-privileges. Caddy has a fixed address that the config lists in trusted_proxies. install.sh writes .env with random passwords, builds the image, starts the stack and creates the first admin from a password read on stdin. The Docker section in docs/server.md covers use, TLS, Postgres, S3, upgrading and what is not covered. The Dockerfile uses the healthcheck subcommand. Derived from the deployment in Skyfuller1303/craftcloud (deploy/compose), written by the same author, MIT OR Apache-2.0, adapted to this repository's TOML-only configuration. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The request used bare line feeds instead of CRLF, and an answer that is not HTTP at all was reported as a bad status. Send CRLF line endings and report "not an HTTP answer" unless the first word is an HTTP version. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
An answer that stopped inside the status line ("HTTP/1.1 200" and then EOF) or
filled the 64 byte buffer without a line end counted as healthy or as a bad
status. Now only a status line that ends in CRLF is read, and the other cases
are errors. Tests cover a truncated line, a line that does not end and a bare
line feed.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
When the server is down, Caddy's error log entry for a failed request carried the full request URI and headers, so an invite code (/join/<code>), a query or a bearer token could end up in the log. The default log now drops request>uri and request>headers. Caddy also skips installing its internal CA into the container, which only produced an error line. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
db-init exported PGPASSWORD, which put the superuser password in the environment of the shell and of psql. It now writes a mode 0600 password file on a tmpfs, passes only PGPASSFILE and removes the file on exit. The db-init service gets a small noexec tmpfs for it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…docs The server started before Caddy and was given 172.29.215.2, the address reserved for Caddy, so Caddy failed to start. The frontend network now hands out dynamic addresses from CC_FRONTEND_POOL (the upper half by default). The docs name the new setting, the error of a data directory with the wrong owner and what was tried with S3. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
render-config.sh read only the first line of a secret file, so a database password with a second line passed the check while db-init, which reads the whole file, set a different password than the one in config.toml. The whole file is read now, one trailing line feed is allowed and any other line feed is refused. The tests cover a second line, an empty second line and the allowed trailing line feed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Compose gives a container its secrets from .env when it is created. After `docker compose run --rm secrets-init`, a later `up -d db-init` started the original secrets-init container again, which wrote the old values back. The docs and the script comment now say to recreate it (`up -d --force-recreate secrets-init`) before restarting the services that read the files. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The locked egui 0.36 crates need rustc 1.95, so the image built from rust:1.94-trixie fails once the workspace's rust-version is raised to 1.95: "rustc 1.94.1 is not supported by the following packages". Rust 1.95 also builds the current workspace, so this does not depend on the order in which the two changes land.
Skyfuller1303
added a commit
to Skyfuller1303/craft-cloud
that referenced
this pull request
Nov 6, 2026
Author
|
Pushed 9003994: the image now builds from With #26 merged, the workspace's |
This was referenced Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A Craft Cloud server can now be run with Docker Compose: one command builds a small, hardened image and starts the server behind Caddy for TLS. SQLite is the default; Postgres and S3 are optional overlays. This is meant as a starting point for M6 packaging; nothing in the server's behaviour changes apart from a new
healthchecksubcommand.Server
craft-cloud-server healthcheck [--addr <host:port>]sendsGET /api/infoto the local listener and exits 0 on a 2xx answer, 1 otherwise. It needs no shell or curl in the image, reads a bounded answer, accepts only a complete HTTP status line and has a short timeout. Numeric IPv4 and bracketed IPv6 addresses work.tests/cli.rscover a healthy answer, error statuses, a refused connection, a non-HTTP answer and a status line that is cut off or too long.Image (
packaging/docker/Dockerfile)nonroot(uid 65532) with no shell. Base images are pinned by digest.craft-cloud-server, defaultserve --config /etc/craft-cloud/config.toml, DockerHEALTHCHECKthrough the new subcommand.Cargo.toml(workspace-version.sh)..dockerignorekeeps.git,targetand local files out of the build context.Compose (
packaging/docker/compose*.yaml)compose.yaml: server, Caddy and a one-shotsecrets-initthat rendersconfig.tomlfrom.envand secret files. Every service is read-only, drops all capabilities (Caddy adds onlyNET_BIND_SERVICE), runs withno-new-privileges, and has memory and pid limits. The server publishes no port; only Caddy does. The server sits on an internal network.compose.postgres.yaml: Postgres 17 on its own internal network and a one-shotdb-initthat creates an unprivilegedcraft_cloudrole owning its database and schema (no superuser, createdb, createrole, replication or bypassrls;PUBLIClosesCREATE). The superuser password reachesdb-initonly through a private passfile on anoexectmpfs, never through the environment.compose.s3.yaml: points the chunk store at an S3-compatible bucket; keys are passed as secret files.acme,internalandcustom(own certificate).trusted_proxiesis set to Caddy's address, so the server's per-client rate limits still count each real client. Caddy's logs drop the request URI and headers, so/join/<code>links and bearer tokens never reach a log.install.shwrites.env(mode 0600), builds the image, starts the stack and creates the first admin with the password read from stdin..envare validated before they go intoconfig.toml; a rejected value is named but never printed. A secret file with more than one line is refused.Docs
docs/server.mdgets a Docker section: quick start, what runs, configuration and secrets, TLS modes, Postgres, S3, the first admin, data, upgrades and backups, password rotation, troubleshooting and what isn't covered.README.mdlinks to it.Testing
cargo test -p craft-cloud-server --lockedpasses (61 lib, 76 api, 13 cli tests), withcargo fmt --check,cargo clippy -p craft-cloud-server --all-targets --locked -- -D warningsandcargo xtask licenses(661 crates on the allow-list).cargo check -p craft-cloud-server --all-targets --lockedpasses on Rust 1.94.restartanddown/up. Two agents synced files through each setup and the downloads matched byte for byte (SHA-256)./api/infoanswers over TLS (internal CA, checked withcurl -k), and the login limiter counted two clients separately: one got 429 after 30 failures while the other still got 401.docker inspectandpsql: the hardening flags and limits above, the Postgres role's privileges, Caddy unable to resolvedb, no password in any container's environment, inspect output, image history or Caddy log.up -ddoes not bring it back.packaging/docker/tests/render-config.shandtests/workspace-version.shpass under Git Bash'ssh; the scripts also ran for real under busybox inside the containers.Not tested
curl.shellcheck, nocargo xtask cirun for this branch (its test step runs out of memory under my 16 GiB limit on unmodifiedmainas well, inan_app_that_misbehaves_is_refused_or_dropped_and_the_rest_go_on, see Agent test an_app_that_misbehaves_is_refused_or_dropped_and_the_rest_go_on needs more than 16 GiB #15).maintoday (egui needs 1.95, andcrates/syncuses if-let guards); only the server crate was checked on 1.94.Left for later
restart: unless-stoppedthen loops. The docs describe it; a clearer message would need a server change.The design follows a container setup from my own prototype (Skyfuller1303/craftcloud, MIT OR Apache-2.0), rewritten for Craft Cloud's server and config.